import React from 'react'
import { incrementAction, decrementAction, waitdecrementAction } from "../../store/actions/countActions"
import { useSelector, useDispatch } from "react-redux"

export default function Count() {
  const dispatch = useDispatch()

  const count = useSelector(state => state.count.count)
  const movieList = useSelector(state => state.movie.movieList)

  const incrementcount = () => {
    dispatch(incrementAction(1))
  }

  const decrementcount = () => {
    dispatch(decrementAction(1))
  }

  const Odddecrementcount = () => {
    if (count % 2 !== 0) {
      dispatch(incrementAction(1))
    }
  }

  const waitdecrementcount = () => {
    dispatch(waitdecrementAction(1))
  }

  return (
    <div>
      <p>值为:{count}</p>
      <h1>接收到{movieList.length}个电影</h1>
      <button onClick={incrementcount}>累加</button>
      <button onClick={decrementcount}>累减</button>
      <button onClick={Odddecrementcount}>奇数加</button>
      <button onClick={waitdecrementcount}>等2秒加</button>
    </div>
  )
}
